package com.zyb.warehouse.config;

import com.zyb.warehouse.filter.LoginFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * Description:登录拦截检查过滤配置
 */
@Configuration
public class FilterConfig {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Bean
    public FilterRegistrationBean filterRegistration() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        //创建过滤器对象
        LoginFilter loginFilter = new LoginFilter();
        loginFilter.setRedisTemplate(redisTemplate);
        //注册过滤器
        filterRegistrationBean.setFilter(loginFilter);
        //拦截所有请求
        filterRegistrationBean.addUrlPatterns("/*");
        return filterRegistrationBean;
    }
}
